/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bm.actions;
import bm.data.Coche;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.Action;

/**
 *
 * @author Anita
 */
public class EditCoche extends Action{

public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        ArrayList <Coche> Listacoches = new ArrayList <Coche>();

           Listacoches = this.ListarCoches();

           //-------------------------->>>>>>>>>>>>>>>>>
           //>>>>>>>>>>>>>>>Implementar algo para que se imprima el arraylist de coches

        /*request.getSession().setAttribute("marca", coche.getMarca());
        request.getSession().setAttribute("modelo", coche.getModelo());
        request.getSession().setAttribute("caracteristicas", coche.getCaracteristicas());
        request.getSession().setAttribute("precio", coche.getPrecio());
        request.getSession().setAttribute("year", coche.getYear());
        request.getSession().setAttribute("descripcion", coche.getDescripcion());
        request.getSession().setAttribute("stock", coche.getStock());
        request.getSession().setAttribute("imagen", coche.getImagen());
        request.setAttribute("coche", coche);*/

        //coche.reset();

        return mapping.findForward("gestionCatalogo");
    }

      private ArrayList <Coche> ListarCoches() throws SQLException{
        // Persistencia de datos
        ArrayList <Coche> Listacoche = new ArrayList <Coche>();

        ConnectBD.connectionBD();

        System.out.println("");

        Listacoche = ConnectBD.obtenerTabla();
        //ConnectBD.insertItemBD("INSERT INTO coche values ('" + coche.getMarca() + "','" + coche.getModelo() + "','" + coche.getCaracteristicas() + "','" +
          //                      coche.getPrecio() + "','" + coche.getYear() + "','" + coche.getDescripcion() + "','" + coche.getStock() + "','" + coche.getImagen() + "')");
        ConnectBD.disconnectBD();

        return Listacoche;

    }

}
